package com.itheima.itheima.controller;

import com.itheima.dto.CheckGroupDto;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    CheckGroupService checkGroupService;

//    @Autowired
//    CheckItemService checkItemService;


    @RequestMapping("/checkallgroup")
    public List<CheckGroup> findallgroup() {
        List<CheckGroup> list = checkGroupService.findall();
        System.out.println(list);
        return list;
    }

    @RequestMapping("/add")
    public Boolean addGroup(@RequestBody CheckGroupDto checkGroupDTO) {
        checkGroupService.add(checkGroupDTO);
        System.out.println(checkGroupDTO);
        return true;
    }

    @RequestMapping("/findbypage")
    public PageResult findbypage(@RequestBody QueryPageBean queryPageBean) {
        System.out.println("分页查询条件"+queryPageBean);
        PageResult pageResult = checkGroupService.findByPage(queryPageBean);
//        return new PageResult();
        System.out.println("pageResult = " + pageResult);
        return pageResult;
    }

    @RequestMapping("/deletebyid")
    public boolean deletebyid(Long id){
        System.out.println(id+"====>id");
        checkGroupService.deleteByGroupId(id);
        return true;
    }
}
